﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace SPA_Prototype.Model
{
    public enum TABLE_NAME { ADMIN, BILL_DETAIL, BILL_MAIN, SERVICE, CURRENCY, CUSTOMER, PERSONEL, PROMOTION };
    class DBDriver
    {
        private static DatabaseDataSet _Dataset;
        private static DatabaseDataSetTableAdapters.TableAdapterManager _Adt;

        // constructor
        public DBDriver(DatabaseDataSet Dataset)
        {
            _Dataset = Dataset;
            _Adt = new DatabaseDataSetTableAdapters.TableAdapterManager();
        }

        // static method : Load and Update
        public static void LoadFromDB(TABLE_NAME Table_Name)
        {
            switch (Table_Name)
            {
                case TABLE_NAME.ADMIN:
                    _Adt.AdminTableTableAdapter.Fill(_Dataset.AdminTable);
                    break;
                case TABLE_NAME.BILL_DETAIL:
                    _Adt.BillDetailsTableTableAdapter.Fill(_Dataset.BillDetailsTable);
                    break;
                case TABLE_NAME.BILL_MAIN:
                    _Adt.BillMainTableTableAdapter.Fill(_Dataset.BillMainTable);
                    break;
                case TABLE_NAME.CURRENCY:
                    _Adt.CurrencyTableTableAdapter.Fill(_Dataset.CurrencyTable);
                    break;
                case TABLE_NAME.CUSTOMER:
                    _Adt.CustomerTableTableAdapter.Fill(_Dataset.CustomerTable);
                    break;
                case TABLE_NAME.PERSONEL:
                    _Adt.PersonelTableTableAdapter.Fill(_Dataset.PersonelTable);
                    break;
                case TABLE_NAME.PROMOTION:
                    _Adt.PromotionTableTableAdapter.Fill(_Dataset.PromotionTable);
                    break;
                case TABLE_NAME.SERVICE:
                    _Adt.ServiceTableTableAdapter.Fill(_Dataset.ServiceTable);
                    break;
            }
        }

        public static void UpdateToDB(TABLE_NAME Table_Name)
        {
            switch (Table_Name)
            {
                case TABLE_NAME.ADMIN:
                    _Adt.AdminTableTableAdapter.Update(_Dataset.AdminTable);
                    break;
                case TABLE_NAME.BILL_DETAIL:
                    _Adt.BillDetailsTableTableAdapter.Update(_Dataset.BillDetailsTable);
                    break;
                case TABLE_NAME.BILL_MAIN:
                    _Adt.BillMainTableTableAdapter.Update(_Dataset.BillMainTable);
                    break;
                case TABLE_NAME.CURRENCY:
                    _Adt.CurrencyTableTableAdapter.Update(_Dataset.CurrencyTable);
                    break;
                case TABLE_NAME.CUSTOMER:
                    _Adt.CustomerTableTableAdapter.Update(_Dataset.CustomerTable);
                    break;
                case TABLE_NAME.PERSONEL:
                    _Adt.PersonelTableTableAdapter.Update(_Dataset.PersonelTable);
                    break;
                case TABLE_NAME.PROMOTION:
                    _Adt.PromotionTableTableAdapter.Update(_Dataset.PromotionTable);
                    break;
                case TABLE_NAME.SERVICE:
                    _Adt.ServiceTableTableAdapter.Update(_Dataset.ServiceTable);
                    break;
            }
        }

    }
}
